package com.itheima.dubbo.web;


import com.itheima.dubbo.DubboClient;
import com.itheima.dubbo.User;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {



    //@DubboReference(cluster ="failfast" )  // 容错机制failfast 快速失败值，调用一次
    // @DubboReference(loadbalance = "roundrobin")  // 负载均衡策略修改 roundrobin:轮询
    // @DubboReference(timeout = 3000)//消费方 设置接口级别的超时时间
//    @DubboReference(methods = {
//            @Method(name = "getUserById" , timeout = 1900 )
//    })
    @DubboReference(check = false, version = "${dubbo.application.version}")
    DubboClient dubboClient;

    @GetMapping("/name")
    public String hello(String name){

        return dubboClient.hello(name);

    }

    @GetMapping("/id")
    public User get(Long id){
        User user = new User();
        user.setId(id);

        RpcContext.getContext().setAttachment("itname","华强");

        return dubboClient.getUserById(user);

    }



}
